<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('采购审核')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-purchase-edit" th:object="${chainPurchase}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">合作公司：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="cooperationId" name="cooperationId" type="hidden" th:value="*{cooperationId}"/>
                    <input class="form-control" disabled type="text" onclick="selectCooperationIdRadio()"
                           id="cooperationName"
                           readonly="true" th:value="*{cooperationName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="commodityId" name="commodityId" type="hidden" th:value="*{commodityId}"/>
                    <input class="form-control" disabled type="text" onclick="selectCommodityIdRadio()"
                           id="commodityName"
                           readonly="true" th:value="*{commodityName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">采购人：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="userId" name="userId" type="hidden" th:value="*{userId}"/>
                    <input class="form-control" disabled type="text" onclick="selectUserIdRadio()" id="userName"
                           readonly="true" th:value="*{userName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品图片：</label>
            <div class="col-sm-8">
                <img th:src="*{image}" width="150" height="100">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">数量：</label>
            <div class="col-sm-8">
                <input name="quantity" disabled th:field="*{quantity}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">金额：</label>
            <div class="col-sm-8">
                <input name="amount" disabled th:field="*{amount}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">运输方式：</label>
            <div class="col-sm-8">
                <select name="transportType" disabled class="form-control m-b"
                        th:with="type=${@dict.getType('transport_type')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{transportType}"></option>
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">审核选项</label>

            <div class="col-sm-10">
                <label class="checkbox-inline">
                    <input type="radio" checked value="3" name="auditType">审核通过</label>
                <label class="checkbox-inline">
                    <input type="radio" value="2" name="auditType">审核不通过</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审核意见：</label>
            <div class="col-sm-8">
                <textarea id="auditInfo" name="auditInfo" class="form-control"></textarea>
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "chain/purchase";
    var cooperationPrefix = ctx + "chain/cooperation"
    var commodityPrefix = ctx + "chain/commodity";
    var userPrefix = ctx + "system/user";
    $("#form-purchase-edit").validate({
        focusCleanup: true
    });

    function selectCooperationIdRadio() {
        var options = {
            title: '选择合作公司',
            url: cooperationPrefix + "/selectCooperation",
            callBack: doCooperationSubmit
        };
        $.modal.openOptions(options);
    }


    function selectCommodityIdRadio() {
        var options = {
            title: '选择商品',
            url: commodityPrefix + "/selectCommodity",
            callBack: doCommoditySubmit
        };
        $.modal.openOptions(options);
    }


    function selectUserIdRadio() {
        var options = {
            title: '选择商品库存',
            url: userPrefix + "/selectUser",
            callBack: doUserSubmit
        };
        $.modal.openOptions(options);
    }

    function doCooperationSubmit(index, layer) {
        var body = $.modal.getChildFrame(index);
        $("#cooperationId").val(body.find("#cooperationId").val());
        $("#cooperationName").val(body.find("#cooperationName").val());
        $.modal.close(index);
    }


    function doCommoditySubmit(index, layer) {
        var body = $.modal.getChildFrame(index);
        $("#commodityId").val(body.find("#commodityId").val());
        $("#commodityName").val(body.find("#commodityName").val());
        $("#amount").val(body.find("#retailPrice").val());
        $.modal.close(index);
    }

    function doUserSubmit(index, layer) {
        var body = $.modal.getChildFrame(index);
        $("#userId").val(body.find("#userId").val());
        $("#userName").val(body.find("#userName").val());
        $.modal.close(index);
    }


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/audit", $('#form-purchase-edit').serialize());
        }
    }

</script>
</body>
</html>